package net.lunjin.dao.impl;

import java.math.BigDecimal;
import java.util.List;

import net.lunjin.bean.NewsRemark;
import net.lunjin.dao.NewsRemarkDao;
import finaler.util.Page;
import finaler.util.PageList;
import finaler.util.SQLUtil;

public class NewsRemarkDaoImpl extends MiddleAbstractDao<NewsRemark> implements
		NewsRemarkDao {

	@Override
	protected Class<NewsRemark> getEntityClass() {
		return NewsRemark.class;
	}

	@Override
	public PageList getNewsRemarkList(Page page) throws Exception {
		StringBuffer whereSql = new StringBuffer();
		whereSql.append(" where newsid = " + page.getParameter("newsId") );
		PageList pageList = new PageList(page);//固定
		StringBuffer sqlCount = new StringBuffer();
		sqlCount.append("select count(1) from newsremark ");
		sqlCount.append( whereSql );
		int dataCount = super.getIntBySql( sqlCount.toString() );//取总
		pageList.setTotal(dataCount);//总数
		
		StringBuffer queryListSql = new StringBuffer();
		queryListSql.append(" select *");
		queryListSql.append(" from newsremark  ");
		queryListSql.append( whereSql );
		queryListSql.append( " order by id asc" );
		SQLUtil pageSQL = new SQLUtil(queryListSql);//固定
		pageSQL.setFirstResult( page.getStart() );//固定
		pageSQL.setMaxResults( page.getRange() );//固定
		List<NewsRemark> dataList = super.findBySqlToBeanList(pageSQL.getSql());//数据集
		pageList.setList(dataList);
		return pageList;
	}

	@Override
	public void deleteRemark(BigDecimal newsId)throws Exception {
		String sqlString  = "delete from newsremark where newsid ="+newsId;
		super.executeSql(sqlString);
	}
	
	
	
}
